home *** CD-ROM | disk | FTP | other *** search
- //: C14:Car.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Public composition
-
- class Engine {
- public:
- void start() const {}
- void rev() const {}
- void stop() const {}
- };
-
- class Wheel {
- public:
- void inflate(int psi) const {}
- };
-
- class Window {
- public:
- void rollup() const {}
- void rolldown() const {}
- };
-
- class Door {
- public:
- Window window;
- void open() const {}
- void close() const {}
- };
-
- class Car {
- public:
- Engine engine;
- Wheel wheel[4];
- Door left, right; // 2-door
- };
-
- int main() {
- Car car;
- car.left.window.rollup();
- car.wheel[0].inflate(72);
- } ///:~
-